/**
 * 23 省赛 Java B组 (8/10)
 * 合并石子
 * https://www.lanqiao.cn/problems/3540/learning/
 */
#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> cnt(n + 1);
  vector<int> color(n + 1);
  for (int i = 1; i <= n; i ++) cin >> cnt[i];
  for (int i = 1; i <= n; i ++) cin >> color[i];
  auto merge_cost = vector(n + 1, vector(n + 1, vector<int>(3, INT_MAX)));
  auto prefix_cnt = vector(n + 1, 0);
  partial_sum(cnt.begin(), cnt.end(), prefix_cnt.begin());
  for (int i = 1; i <= n; i ++) merge_cost[i][i][color[i]] = 0;
  for (int len = 2; len <= n; len ++) {
    for (int l = 1; l + len - 1 <= n; l ++) {
      int r = l + len - 1;
      for (int mid = l; mid < r; mid ++) {
        for (int c = 0; c < 3; c ++) {
          int lastc = (c + 2) % 3;
          if (merge_cost[l][mid][lastc] != INT_MAX && merge_cost[mid + 1][r][lastc] != INT_MAX) {
            merge_cost[l][r][c] = min(merge_cost[l][r][c],
                                      merge_cost[l][mid][lastc] + merge_cost[mid + 1][r][lastc] +
                                      prefix_cnt[r] - prefix_cnt[l - 1]);
          }
        }
      }
    }
  }
  debug(merge_cost);
  auto graph = vector(n + 1, vector<pair<int, int>>());
  for (int i = 1; i <= n; i ++) {
    for (int j = i; j <= n; j ++) {
      int min_cost = *min_element(merge_cost[i][j].begin(), merge_cost[i][j].end());
      if (min_cost == INT_MAX) continue;
      graph[i].emplace_back(j + 1, min_cost);
    }
  }
  debug(graph);
  auto dp = vector(n + 2, vector(n + 2, INT_MAX));
  dp[1][0] = 0;
  for (int i = 1; i <= n; i ++) {
    for (int cnt = 0; cnt <= n; cnt ++) {
      if (dp[i][cnt] == INT_MAX) continue;
      for (auto [j, cost] : graph[i]) {
        dp[j][cnt + 1] = min(dp[j][cnt + 1], dp[i][cnt] + cost);
      }
    }
  }
  for (int cnt = 0; cnt <= n; cnt ++) {
    if (dp[n + 1][cnt] != INT_MAX) {
      cout << cnt << ' ' << dp[n + 1][cnt] << endl;
      break;
    }
  }
}